const getQuestionBank = () => {
	return new Promise((resolve, reject) => {
		uniCloud.callFunction({
			name: 'getQuestionBank',
			success: (data) => {
				const res = data.result.data
				if (Array.isArray(res)) {
					resolve(res);
				} else {
					reject()
				}
			},
			fail: () => {
				reject()
			}
		});
	})
}

export const getQuestionBankList = async (params = {}) => {
	const defaultParams = {
		pageNo: 1,
		pageSize: 10,
	}
	for (const key in defaultParams) {
		if (!params[key]) {
			params[key] = defaultParams[key]
		}
	}
	const list = await getQuestionBank()
	return list.filter((item, index) => {
		// 例如:下标0要在 [-1, 10]之间, 只能取0-9
		if (index > (params.pageNo - 1) * params.pageSize - 1) {
			return true
		} else if (index < params.pageNo * params.pageSize) {
			return true
		}
	})
}